<template>
  <div class="lb-system-other">
    <top-nav />
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="subForm"
        :rules="subFormRules"
        ref="subForm"
        label-width="160px"
      >
   <el-form-item label="Listen地址" prop="listen_url">
     <el-input
       v-model="subForm.listen_url"
       placeholder="请输入Listen地址"
     ></el-input>
    
   </el-form-item>
   <el-form-item label="Listen key" prop="listen_key">
     <el-input
       v-model="subForm.listen_key"
       placeholder="请输入Listen key"
     ></el-input>
    
   </el-form-item>
   <el-form-item label="push Key" prop="push_key">
     <el-input
       v-model="subForm.push_key"
       placeholder="请输入push Key"
     ></el-input>
    
   </el-form-item>
   
   <el-form-item label="push Url" prop="push_url">
     <el-input
       v-model="subForm.push_url"
       placeholder="请输入push Url"
     ></el-input>
    
   </el-form-item>
   <el-form-item label="pull Key" prop="pull_key">
     <el-input
       v-model="subForm.pull_key"
       placeholder="请输入pull Key"
     ></el-input>
    
   </el-form-item>
   
   <el-form-item label="pull Url" prop="pull_url">
     <el-input
       v-model="subForm.pull_url"
       placeholder="请输入pull Url"
     ></el-input>
    
   </el-form-item>
      
        <el-form-item>
          <lb-button @click="submitForm" type="primary" v-preventReClick>{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      subForm: {
		listen_url:'',
		listen_key:'',
		push_key:'',
		push_url:'',
		pull_key:'',
		pull_url:''
      },
      subFormRules: {
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  computed: {
    ...mapState({
      routesItem: state => state.routes
    })
  },
  methods: {
    async getFormInfo () {
      let { code, data } = await this.$api.system.configInfo()
      if (code !== 200) return
      for (let key in this.subForm) {
        this.subForm[key] = data[key]
      }
    },
    getFile (file, key) {
      let len = file.length - 1
      this.subForm[key] = file[len].url
    },
    submitForm () {
  
          let { subForm } = this
          this.$api.system.configUpdate(subForm).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
     
    }
  },
  filters: {
    handleFileName (url) {
      let text = '请上传文件'
      if (url) {
        text = url.substring(url.lastIndexOf('/') + 1)
      }
      return text
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-system-other {
  width: 100%;

  .el-input,
  .el-select {
    width: 300px;
  }
}
</style>
